function config_tomcat_nginx(){
	#Install JAVA JDK 
	TOMCAT_VER="8.0.50"
	JAVA_VER="1.8.0_131"
	JAVA_DIR="/usr/java"
	TOMCAT_DIR="/usr/local"
	JAVA_SOFT="jdk${JAVA_VER}.tar.gz"
	TOMCAT_SOFT="apache-tomcat-${TOMCAT_VER}.tar.gz"
	grep -ai "^export" /etc/profile|grep -ai "JAVA_HOME" >/dev/null
	if [ $? -ne 0 ];then
	#Install JAVA JDK
	ls -l $JAVA_SOFT 
	tar -xzvf $JAVA_SOFT
	mkdir -p $JAVA_DIR/
	\mv jdk$JAVA_VER $JAVA_DIR/
	ls -l $JAVA_DIR/jdk$JAVA_VER/
	$JAVA_DIR/jdk$JAVA_VER/bin/java -version
	cat>>/etc/profile<<-EOF
	export JAVA_HOME=$JAVA_DIR/jdk$JAVA_VER
	export CLASSPATH=\$CLASSPATH:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib
	EOF
	source /etc/profile
	fi

	shift 1
	NUM=`ls /usr/local/|grep -c tomcat`
	if [ $NUM -eq 0 ];then
		cp -r tomcat /usr/local/tomcat_$*
		exit 0
	fi
	#--------------------------------
	#VHOSTS=$1
	VHOSTS_NUM=`ls $NGINX_CONF/domains/|grep -c $*`
	SERVER_NUM=`grep -c "127" $NGINX_CONF/domains/$*`
	SERVER_NUM_1=`expr $SERVER_NUM + 1`
	rm -rf /tmp/.port.txt
	for i in `find /usr/local/ -maxdepth 1 -name "tomcat*"`;do
		grep "port" $i/conf/server.xml |egrep -v "\--|8080|SSLEnabled"|awk '{print $2}'|sed 's/port=//g;s/\"//g'|sort -nr >>/tmp/.port.txt
	done
	MAX_PORT=`cat /tmp/.port.txt|grep -v 8443|sort -nr|head -1`
	PORT_1=`expr $MAX_PORT - 2000 + 1`
	PORT_2=`expr $MAX_PORT - 1000 + 1`
	PORT_3=`expr $MAX_PORT + 1`
	if [ $*_NUM -eq 1 ];then
		read -p "The $* is exists,You sure create mulit Tomcat for the $*? yes or no " INPUT
		if [ $INPUT == "YES" -o $INPUT == "Y" -o $INPUT == "yes" ];then
			cp -r tomcat /usr/local/tomcat_${VHOSTS}_${SERVER_NUM_1}
			sed -i "s/6001/$PORT_1/g" /usr/local/tomcat_${VHOSTS}_${SERVER_NUM_1}/conf/server.xml
			sed -i "s/7001/$PORT_2/g" /usr/local/tomcat_${VHOSTS}_${SERVER_NUM_1}/conf/server.xml
			sed -i "s/8001/$PORT_3/g" /usr/local/tomcat_${VHOSTS}_${SERVER_NUM_1}/conf/server.xml
			sed -i "/^upstream/a		server 127.0.0.1:${PORT_2} weight=1 max_fails=2 fail_timeout=30s;" $NGINX_CONF/domains/$*
			exit 0
		fi	
		exit
	fi
		cp -r tomcat /usr/local/tomcat_$*
        cp -r xxx.jfedu.net $NGINX_CONF/domains/$*
        sed -i "s/VHOSTS/$*/g" $NGINX_CONF/domains/$*
        sed -i "s/xxx/$*/g" $NGINX_CONF/domains/$*
		sed -i "s/7001/${PORT_2}/g" $NGINX_CONF/domains/$*
		#######config tomcat
		sed -i "s/6001/$PORT_1/g" /usr/local/tomcat_${VHOSTS}/conf/server.xml
        sed -i "s/7001/$PORT_2/g" /usr/local/tomcat_${VHOSTS}/conf/server.xml
        sed -i "s/8001/$PORT_3/g" /usr/local/tomcat_${VHOSTS}/conf/server.xml

}
if [ ! -d $NGINX_CONF -o ! -d  /usr/java/$JDK_DIR ];then
	install_nginx
	install_tomcat
fi
config_tomcat_nginx $1